var PayersModel = function() {
	this.checkAllPayers = $("#checkAllPayers");
	this.checkPayer = $(".checkPayer");
};

var Payers = function(model) {
	
	var checkAll = function(){
		var checkbox = $(this);
		if(checkbox.is(":checked")){
			model.checkPayer.each(function(i){
				$(this).attr("checked", "checked");
			});
		} else {
			model.checkPayer.each(function(i){
				$(this).removeAttr("checked");
			});
		}
		
	};
	
	var uncheckTopCheckbox = function() {
		model.checkPayer.each(function(i){
			if(!$(this).is(":checked")){
				model.checkAllPayers.removeAttr("checked");
			}
		});
	};
	
	this.init = function(){
		model.checkAllPayers.click(checkAll);
		model.checkPayer.bind("click", uncheckTopCheckbox);
	};
};